package TCP.Test;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client1 {
    public static void main(String[] args) throws Exception {
        Scanner input = new Scanner(System.in);
        while (true) {
            Socket socket = new Socket("127.0.0.1", 8888);
            OutputStream os = socket.getOutputStream();
            System.out.println("请输入你想说的话：");
            String s = input.next();
            os.write(s.getBytes());
            socket.shutdownOutput();

            InputStream is = socket.getInputStream();
            int len;
            byte[] a = new byte[1024];
            while ((len = is.read(a)) != -1){
                String str = new String(a,0,len);
                System.out.println(str);
                if(str.indexOf("登录成功")==-1){
                    break;
                }else {
                    System.exit(1);
                }
            }
        }

    }
}
